import numpy as np
from apps.fmcw.fmcw_conf import FmcwConf as FC

def compare_t(t):
    # 文件比较
    t_csv = 'D:/research/iragent/work/FMCW-MIMO-Radar-Simulation/t.csv'
    max_diff = 0.0
    err_cnt = 0
    with open(t_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(L0):
                if abs(float(arrs0[i]) - t[i]) > max_diff:
                    max_diff = abs(float(arrs0[i]) - t[i])
                if abs(float(arrs0[i])) < 1e-10 and abs(float(arrs0[i]) - t[i]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(float(arrs0[i]) - t[i]) / abs(float(arrs0[i]) + 1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                if i % 1000 == 0:
                    print(f'处理完成：{i}; {float(arrs0[i])} vs {t[i]};   errors: {err_cnt};')
    print(f't 错误记录数：{err_cnt}; max_diff: {max_diff};')

def compare_t_onePulse(t_onePulse):
    # 文件比较
    t_onePulse_csv = 'D:/research/iragent/work/FMCW-MIMO-Radar-Simulation/t_onePulse.csv'
    max_diff = 0.0
    err_cnt = 0
    with open(t_onePulse_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(L0):
                if abs(float(arrs0[i]) - t_onePulse[i]) > max_diff:
                    max_diff = abs(float(arrs0[i]) - t_onePulse[i])
                if abs(float(arrs0[i])) < 1e-10 and abs(float(arrs0[i]) - t_onePulse[i]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(float(arrs0[i]) - t_onePulse[i]) / abs(float(arrs0[i])+1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                if i % 1 == 0:
                    print(f'处理完成：{i}; {float(arrs0[i])} vs {t_onePulse[i]};   errors: {err_cnt};')
    print(f't_onePulse 错误记录数：{err_cnt}; max_diff: {max_diff};')    

def compare_delays_tar(delays_tar, csv_fn):
    # 文件比较
    delays_tar_csv = f'D:/research/iragent/work/FMCW-MIMO-Radar-Simulation/{csv_fn}'
    max_diff = 0.0
    idx = 0
    err_cnt = 0
    with open(delays_tar_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            for i in range(L0):
                if abs(float(arrs0[i]) - delays_tar[0][idx][i]) > max_diff:
                    max_diff = abs(float(arrs0[i]) - delays_tar[0][idx][i])
                if abs(float(arrs0[i])) < 1e-10 and abs(float(arrs0[i]) - delays_tar[0][idx][i]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(float(arrs0[i]) - delays_tar[0][idx][i]) / abs(float(arrs0[i])+1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                if i % 1000 == 0:
                    print(f'处理完成：{idx}_{i}; {float(arrs0[i])} vs {delays_tar[0][idx][i]};   errors: {err_cnt};')
            idx += 1
    print(f'{csv_fn} 错误记录数：{err_cnt}; max_diff: {max_diff};')   

def compare_phase_x(phase_x, csv_fn):
    # 文件比较
    phase_x_csv = f'D:/research/iragent/work/FMCW-MIMO-Radar-Simulation/{csv_fn}'
    max_diff = 0.0
    err_cnt = 0
    with open(phase_x_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(L0):
                if abs(float(arrs0[i]) - phase_x[i]) > max_diff:
                    max_diff = abs(float(arrs0[i]) - phase_x[i])
                if abs(float(arrs0[i])) < 1e-10 and abs(float(arrs0[i]) - phase_x[i]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(float(arrs0[i]) - phase_x[i]) / abs(float(arrs0[i])+1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！ {float(arrs0[i])} <=> {phase_x[i]} diff: {abs(float(arrs0[i]) - phase_x[i]) / abs(float(arrs0[i])+1e-38)}; ?????')
                    err_cnt += 1
                if i % 1 == 0:
                    print(f'处理完成：{i}; {float(arrs0[i])} vs {phase_x[i]};   errors: {err_cnt};')
    print(f'{csv_fn} 错误记录数：{err_cnt}; max_diff: {max_diff};')         

def compare_signal_x(signal_x, csv_fn):
    # 文件比较
    signal_x_csv = f'D:/research/iragent/work/FMCW-MIMO-Radar-Simulation/{csv_fn}'
    max_diff = 0.0
    err_cnt = 0
    with open(signal_x_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(0, L0, 2):
                if abs(complex(float(arrs0[i]),float(arrs0[i+1])) - signal_x[i//2]) > max_diff:
                    max_diff = abs(complex(float(arrs0[i]),float(arrs0[i+1])) - signal_x[i//2])
                if abs(complex(float(arrs0[i]), float(arrs0[i+1]))) < 1e-10 and abs(complex(float(arrs0[i]),float(arrs0[i+1])) - signal_x[i//2]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(complex(float(arrs0[i]), float(arrs0[i+1])) - signal_x[i//2]) / abs(complex(float(arrs0[i]), float(arrs0[i+1]))+1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！ {complex(float(arrs0[i]), float(arrs0[i+1]))} <=> {signal_x[i//2]} diff: {abs(complex(float(arrs0[i]), float(arrs0[i+1])) - signal_x[i//2]) / abs(complex(float(arrs0[i]), float(arrs0[i+1]))+1e-38)}; ?????')
                    err_cnt += 1
                if i % 1000 == 0:
                    print(f'处理完成：{i}; {complex(float(arrs0[i]), float(arrs0[i+1]))} vs {signal_x[i//2]};   errors: {err_cnt};')
    print(f'{csv_fn} 错误记录数：{err_cnt}; max_diff: {max_diff};')         
            
def compare_mixed(mixed):
    # 文件比较
    mixed_csv = f'D:/research/iragent/work/FMCW-MIMO-Radar-Simulation/mixed.csv'
    max_diff = 0.0
    err_cnt = 0
    rxi = 0
    with open(mixed_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(0, L0, 2):
                mtcv = complex(float(arrs0[i]),float(arrs0[i+1]))
                if abs(mtcv - mixed[0][rxi][i//2]) > max_diff:
                    max_diff = abs(mtcv - mixed[0][rxi][i//2])
                if abs(mtcv) < 1e-10 and abs(mtcv - mixed[0][rxi][i//2]) > 0.001:
                    print(f'{rxi}_{i}.1: K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(mtcv - mixed[0][rxi][i//2]) / abs(mtcv+1e-38) > 0.001:
                    print(f'{rxi}_{i}.2: 值不一致! {mtcv} <=> {mixed[0][rxi][i//2]} diff: {abs(mtcv - mixed[0][rxi][i//2]) / abs(mtcv+1e-38)}; ?????')
                    err_cnt += 1
                if i % 100000 == 0:
                    print(f'处理完成：{rxi}_{i}; {mtcv} vs {mixed[0][rxi][i//2]};   errors: {err_cnt};')
            rxi += 1
    print(f'mixed 错误记录数：{err_cnt}; max_diff: {max_diff};')         

def compare_RDC(RDC):
    # 文件比较
    RDC_csv = f'./work/FMCW-MIMO-Radar-Simulation/RDC.csv'
    ridx = 0 # range index
    didx = 0 # doppler index
    aidx = 0 # antenna index
    max_diff = 0.0
    err_cnt = 0
    rxi = 0
    with open(RDC_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            # 每行numTx*numRX
            for i in range(0, L0, 2):
                rcv = complex(float(arrs0[i]), float(arrs0[i+1]))
                if abs(rcv - RDC[ridx][didx][i//2]) > max_diff:
                    max_diff = abs(rcv - RDC[ridx][didx][i//2])
                if abs(rcv) < 1e-38 and abs(rcv - RDC[ridx][didx][i//2]) > 0.001:
                    print(f'case 1: {ridx}_{didx}_{i//2} 值不一致; {rcv} vs {RDC[ridx][didx][i//2]};')
                    err_cnt += 1
                elif abs(rcv - RDC[ridx][didx][i//2]) / abs(rcv) > 0.001:
                    print(f'case 2: {ridx}_{didx}_{i//2} 值不一样; {rcv} vs {RDC[ridx][didx][i//2]};')
                    err_cnt += 1
                if (ridx*FC.numChirps*FC.numCPI*FC.numTX*FC.numRX + didx*FC.numTX*FC.numRX + i//2) % 100000:
                    print(f'处理：{ridx}_{didx}_{i//2}，进度：{(ridx*FC.numChirps*FC.numCPI*FC.numTX*FC.numRX + didx*FC.numTX*FC.numRX + i//2)/(FC.numADC*FC.numChirps*FC.numCPI*FC.numTX*FC.numRX)};')
            didx += 1
            if didx == FC.numChirps*FC.numCPI:
                didx = 0
                ridx += 1
                if ridx == FC.numADC:
                    ridx = 0
    print(f'RDC 错误记录数：{err_cnt}; max_diff: {max_diff};')         
            
def compare_RD_frame_x(RD_frame, csv_fn):
    # 文件比较
    RD_frame_csv = f'./work/FMCW-MIMO-Radar-Simulation/{csv_fn}'
    ridx = 0 # range index
    didx = 0 # doppler index
    aidx = 0 # antenna index
    max_diff = 0.0
    err_cnt = 0
    rxi = 0
    with open(RD_frame_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            # 每行numTx*numRX
            for i in range(0, L0, 2):
                rcv = complex(float(arrs0[i]), float(arrs0[i+1]))
                if abs(rcv - RD_frame[ridx][didx][i//2]) > max_diff:
                    max_diff = abs(rcv - RD_frame[ridx][didx][i//2])
                if abs(rcv) < 1e-38 and abs(rcv - RD_frame[ridx][didx][i//2]) > 0.001:
                    print(f'case 1: {ridx}_{didx}_{i//2} 值不一致; {rcv} vs {RD_frame[ridx][didx][i//2]};')
                    err_cnt += 1
                elif abs(rcv - RD_frame[ridx][didx][i//2]) / abs(rcv) > 0.001:
                    print(f'case 2: {ridx}_{didx}_{i//2} 值不一样; {rcv} vs {RD_frame[ridx][didx][i//2]};')
                    err_cnt += 1
                if (ridx*FC.numChirps*FC.numTX*FC.numRX + didx*FC.numTX*FC.numRX + i//2) % 1000:
                    print(f'处理：{ridx}_{didx}_{i//2}，进度：{(ridx*FC.numChirps*FC.numTX*FC.numRX + didx*FC.numTX*FC.numRX + i//2)/(FC.numADC*FC.numChirps*FC.numTX*FC.numRX)};')
            didx += 1
            if didx == FC.numChirps:
                didx = 0
                ridx += 1
                if ridx == FC.numADC:
                    ridx = 0
    print(f'RD_frame 错误记录数：{err_cnt}; max_diff: {max_diff};')      


def compare_fft2_result(fft2_result):
    # 文件比较
    fft2_result_csv = f'./work/FMCW-MIMO-Radar-Simulation/fft2_result.csv'
    ridx = 0 # range index
    didx = 0 # doppler index
    aidx = 0 # antenna index
    max_diff = 0.0
    err_cnt = 0
    rxi = 0
    with open(fft2_result_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            # 每行numTx*numRX
            for i in range(0, L0, 2):
                rcv = complex(float(arrs0[i]), float(arrs0[i+1]))
                if abs(rcv - fft2_result[ridx][didx][i//2]) > max_diff:
                    max_diff = abs(rcv - fft2_result[ridx][didx][i//2])
                if abs(rcv) < 1e-38 and abs(rcv - fft2_result[ridx][didx][i//2]) > 0.001:
                    print(f'case 1: {ridx}_{didx}_{i//2} 值不一致; {rcv} vs {fft2_result[ridx][didx][i//2]};')
                    err_cnt += 1
                elif abs(rcv - fft2_result[ridx][didx][i//2]) / abs(rcv) > 0.001:
                    print(f'case 2: {ridx}_{didx}_{i//2} 值不一样; {rcv} vs {fft2_result[ridx][didx][i//2]};')
                    err_cnt += 1
                if (ridx*FC.numChirps*FC.numTX*FC.numRX + didx*FC.numTX*FC.numRX + i//2) % 1000:
                    print(f'处理：{ridx}_{didx}_{i//2}，进度：{(ridx*FC.numChirps*FC.numTX*FC.numRX + didx*FC.numTX*FC.numRX + i//2)/(FC.numADC*FC.numChirps*FC.numTX*FC.numRX)};')
            didx += 1
            if didx == FC.numChirps:
                didx = 0
                ridx += 1
                if ridx == FC.numADC:
                    ridx = 0
    print(f'fft2_result 错误记录数：{err_cnt}; max_diff: {max_diff};')    


def compare_RDMs(RDMs):
    # 文件比较
    RDMs_csv = f'./work/FMCW-MIMO-Radar-Simulation/RDMs.csv'
    idx0, idx1, idx2, idx3 = 0, 0, 0, 0
    max_diff = 0.0
    err_cnt = 0
    with open(RDMs_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            # RDMs: N_range, N_Dopp, numTX * numRX, numCPI
            for i in range(0, L0, 2):
                rcv = complex(float(arrs0[i]), float(arrs0[i+1]))
                if abs(rcv - RDMs[idx0][idx1][idx2][i//2]) > max_diff:
                    max_diff = abs(rcv - RDMs[idx0][idx1][idx2][i//2])
                if abs(rcv) < 1e-38 and abs(rcv - RDMs[idx0][idx1][idx2][i//2]) > 0.001:
                    print(f'case 1: {idx0}_{idx1}_{idx2}_{i//2} 值不一致; {rcv} vs {RDMs[idx0][idx1][idx2][i//2]};')
                    err_cnt += 1
                elif abs(rcv - RDMs[idx0][idx1][idx2][i//2]) / abs(rcv) > 0.001:
                    print(f'case 2: {idx0}_{idx1}_{idx2}_{i//2} 值不一样; {rcv} vs {RDMs[idx0][idx1][idx2][i//2]};')
                    err_cnt += 1
                if (idx0*FC.N_Dopp*FC.numTX*FC.numRX*FC.numCPI + idx1*FC.numTX*FC.numRX*FC.numCPI + idx2*FC.numCPI + i//2) % 100000:
                    print(f'处理：{idx0}_{idx1}_{idx2}_{i//2}，进度：{(idx0*FC.N_Dopp*FC.numTX*FC.numRX*FC.numCPI + idx1*FC.numTX*FC.numRX*FC.numCPI + idx2*FC.numCPI + i//2)/(FC.N_range*FC.N_Dopp*FC.numTX*FC.numRX*FC.numCPI)};')
                idx3 += 1
                if idx3 == FC.numCPI:
                    idx3 = 0
                    idx2 += 1
                    if idx2 == FC.numTX*FC.numRX:
                        idx2 = 0
                        idx1 += 1
                        if idx1 == FC.N_Dopp:
                            idx1 = 0
                            idx0 += 1
                            if idx0 == FC.N_range:
                                idx0 = 0
    print(f'RDMs 错误记录数：{err_cnt}; max_diff: {max_diff};')    

def compare_a1(a1):
    # 文件比较
    a1_csv = f'./work/FMCW-MIMO-Radar-Simulation/a1.csv'
    max_diff = 0.0
    err_cnt = 0
    idx = 0
    with open(a1_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(0, L0, 2):
                mtcv = complex(float(arrs0[i]),float(arrs0[i+1]))
                if abs(mtcv - a1[idx][i//2]) > max_diff:
                    max_diff = abs(mtcv - a1[idx][i//2])
                if abs(mtcv) < 1e-10 and abs(mtcv - a1[idx][i//2]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(mtcv - a1[idx][i//2]) / abs(mtcv+1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！ {complex(float(arrs0[i]), float(arrs0[i+1]))} <=> {signal_x[i//2]} diff: {abs(complex(float(arrs0[i]), float(arrs0[i+1])) - signal_x[i//2]) / abs(complex(float(arrs0[i]), float(arrs0[i+1]))+1e-38)}; ?????')
                    err_cnt += 1
                if i % 10 == 0:
                    print(f'处理完成：{i}; {mtcv} vs {a1[idx][i//2]};   errors: {err_cnt};')
            idx += 1
    print(f'a1.csv 错误记录数：{err_cnt}; max_diff: {max_diff};')            

def compare_Rxx(Rxx):
    # 文件比较
    a1_csv = f'./work/FMCW-MIMO-Radar-Simulation/Rxx.csv'
    max_diff = 0.0
    err_cnt = 0
    idx = 0
    with open(a1_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(0, L0, 2):
                mtcv = complex(float(arrs0[i]),float(arrs0[i+1]))
                if abs(mtcv - Rxx[(i//2)//8][(i//2)%8]) > max_diff:
                    max_diff = abs(mtcv - Rxx[(i//2)//8][(i//2)%8])
                if abs(mtcv) < 1e-10 and abs(mtcv - Rxx[(i//2)//8][(i//2)%8]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(mtcv - Rxx[(i//2)//8][(i//2)%8]) / abs(mtcv+1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！ {complex(float(arrs0[i]), float(arrs0[i+1]))} <=> {Rxx[(i//2)//8][(i//2)%8]} diff: {abs(complex(float(arrs0[i]), float(arrs0[i+1])) - Rxx[(i//2)//8][(i//2)%8]) / abs(complex(float(arrs0[i]), float(arrs0[i+1]))+1e-38)}; ?????')
                    err_cnt += 1
                if i % 10 == 0:
                    print(f'处理完成：{i}; {mtcv} vs {Rxx[(i//2)//8][(i//2)%8]};   errors: {err_cnt};')
            idx += 1
    print(f'a1.csv 错误记录数：{err_cnt}; max_diff: {max_diff};')            

def compare_RDM_mask(RDM_mask):
    # 文件比较
    RDM_mask_csv = f'./work/FMCW-MIMO-Radar-Simulation/RDM_mask.csv'
    max_diff = 0.0
    err_cnt = 0
    idx = 0
    with open(RDM_mask_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            for i in range(L0):
                mtcv = float(arrs0[i])
                if abs(mtcv - RDM_mask[idx][i]) > max_diff:
                    max_diff = abs(mtcv - RDM_mask[idx][i])
                if abs(mtcv) < 1e-10 and abs(mtcv - RDM_mask[idx][i]) > 0.001:
                    print(f'111 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！')
                    err_cnt += 1
                elif abs(mtcv - RDM_mask[idx][i]) / abs(mtcv+1e-38) > 0.001:
                    print(f'222 K############# !!!!!!!!! 值不一致！！！！！！！！！！！！！！ {mtcv} <=> {RDM_mask[idx][i]} diff: {abs(mtcv - RDM_mask[idx][i]) / abs(mtcv)}; ?????')
                    err_cnt += 1
                if i % 10 == 0:
                    print(f'处理完成：{i}; {mtcv} vs {RDM_mask[idx][i]};   errors: {err_cnt};')
            idx += 1
    print(f'RDM_mask.csv 错误记录数：{err_cnt}; max_diff: {max_diff};')            

def compare_rangeFFT(rangeFFT):
    # 文件比较
    rangeFFT_csv = f'./work/FMCW-MIMO-Radar-Simulation/rangeFFT.csv'
    idx0, idx1, idx2 = 0, 0, 0
    Dim0, Dim1, Dim2 = FC.numADC, FC.numChirps*FC.numCPI, FC.numTX*FC.numRX
    max_diff = 0.0
    err_cnt = 0
    with open(rangeFFT_csv, 'r', encoding='utf-8') as fd:
        for row in fd:
            row = row.strip()
            arrs0 = row.split(',')
            L0 = len(arrs0) - 1
            print(f'L0: {L0}; ???????????')
            # RDMs: N_range, N_Dopp, numTX * numRX, numCPI
            for i in range(0, L0, 2):
                rcv = complex(float(arrs0[i]), float(arrs0[i+1]))
                if abs(rcv - rangeFFT[idx0][idx1][i//2]) > max_diff:
                    max_diff = abs(rcv - rangeFFT[idx0][idx1][i//2])
                if abs(rcv) < 1e-38 and abs(rcv - rangeFFT[idx0][idx1][i//2]) > 0.001:
                    print(f'case 1: {idx0}_{idx1}_{idx2}_{i//2} 值不一致; {rcv} vs {rangeFFT[idx0][idx1][i//2]};')
                    err_cnt += 1
                    exit(0)
                elif abs(rcv - rangeFFT[idx0][idx1][i//2]) / abs(rcv) > 0.001:
                    print(f'case 2: {idx0}_{idx1}_{idx2}_{i//2} 值不一样; {rcv} vs {rangeFFT[idx0][idx1][i//2]};')
                    err_cnt += 1
                    exit(0)
                if (idx0*Dim1*Dim2 + idx1*Dim2 + i//2) % 100000:
                    print(f'处理：{idx0}_{idx1}_{idx2}_{i//2}，进度：{(idx0*Dim1*Dim2 + idx1*Dim2 + i//2)/(Dim0*Dim1*Dim2)};')
                idx2 += 1
                if idx2 == Dim2:
                    idx2 = 0
                    idx1 += 1
                    if idx1 == Dim1:
                        idx1 = 0
                        idx0 += 1
                        if idx0 == Dim0:
                            idx0 = 0
    print(f'rangeFFT 错误记录数：{err_cnt}; max_diff: {max_diff};')    